package sysu.el.array.type.algors;
import java.lang.reflect.Method;

import sysu.el.array.type.functors.FunBType;

public class ArrFilterType {
	// Todo
	public static<T> int[] apply(int arr_num, T[] arr, Method m){
		return null;}
	
	public static<T> int[] apply(int arr_num, T[] arr, FunBType<T> fun){
		int c = 0;
		for (int i=0; i<arr_num; i++){
			if (fun.apply(arr[i]))
				arr[c++] = arr[i]; 
		}
		int[] new_arr = new int[c];
		System.arraycopy(arr, 0, new_arr, 0, c);
		return new_arr;
	}
	
	public static<T> int applyFast(int arr_num, T[] arr, FunBType<T> fun){
		int c = 0;
		for (int i=0; i<arr_num; i++){
			if (fun.apply(arr[i]))
				arr[c++] = arr[i];
		}
		return c;
	}
}
